//
//  CardImageManager.m
//  CardWarrior
//
//  Created by Tekka Xie on 12-4-21.
//  Copyright (c) 2012年 Tencent. All rights reserved.
//

#import "CardImageManager.h"

@interface CardImageManager()
{
	NSMutableArray* mCardImageArray;  
}
@end

@implementation CardImageManager

static CardImageManager* pInstance = nil;

+ (id)sharedInstance
{
    if (pInstance == nil)
        pInstance = [[CardImageManager alloc] init];    
    return pInstance;
}

- (id)init
{
    if (self = [super init])
    {
        mCardImageArray = [[NSMutableArray alloc] initWithCapacity:52];
	
        @autoreleasepool 
        {
            for (int i = 1; i <= 4; i++) 
            {
                NSString* floorName = [NSString stringWithFormat:@"CardFloor%d.png", i];
                UIImage*  floorImage = [UIImage imageNamed:floorName];
            
                NSString* middleName = [NSString stringWithFormat:@"CardMiddle%d.png", i] ;
                UIImage*  middleImage = [UIImage imageNamed:middleName] ;
            
                for (int j = 1; j <= 13; j++) 
                {
                    NSString* fontName = [NSString stringWithFormat:@"CardFont%02d.png", j];
                    UIImage*  fontImage = [UIImage imageNamed:fontName];
                
                    UIGraphicsBeginImageContext(floorImage.size) ;
                
                    [floorImage	drawAtPoint:CGPointMake(0.0, 0.0)];						
                    [fontImage drawAtPoint:CGPointMake(0.0, 0.0)];
                    [middleImage drawAtPoint:CGPointMake(0.0, 0.0)];
                
                    UIImage* finalImage = UIGraphicsGetImageFromCurrentImageContext();
                    [mCardImageArray addObject:finalImage];
                
                    UIGraphicsEndImageContext() ;
                }
            }
        }
    }
    
    return self;
}

- (UIImage*)GetImage:(int)index ;
{
    return [mCardImageArray objectAtIndex:index];
}

- (NSMutableArray*)GetImageArray;
{
    return mCardImageArray;
}

@end
